package com.cby.operation.sdk.http

import com.cby.operation.login.LoginManager
import com.cby.operation.login.data.InternalUser
import com.cby.operation.sdk.SdkConfiguration
import com.cby.operation.sdk.util.UserUtils
import kotlin.collections.HashMap

/**
 * 描述信息: url工具类
 *
 * @author xuzhiwei
 * @create 2020/8/13
 */
object UrlHelper {
    /**
     * 包名
     */
    private const val KEY_PACKAGE_NAME = "packageName"

    /**
     * sdk版本号
     */
    private const val KEY_SDK_VERSION = "sdkVersion"
    private const val KEY_HOST = "KBU"
    private const val SDK_HOST = "https://sdk.3839app.com/"

    //private static final String SDK_HOST = "http://t.sdk.3839app.com/";
    @JvmStatic
    fun buildSdkUrl(path: String): String {
        return SDK_HOST + path
    }

    @JvmStatic
    val commonHeader: Map<String, String>
        get() {
            val commonHeader: MutableMap<String, String> = HashMap()
            commonHeader[KEY_PACKAGE_NAME] = SdkConfiguration.packageName
            commonHeader[KEY_SDK_VERSION] = SdkConfiguration.sdkVersion
            return commonHeader
        }

    /**
     * 获取授权的header信息
     * @return
     */
    val authHeaders: Map<String, String>
        get() {
            val paramMap = HashMap<String, String>()

            paramMap[KEY_PACKAGE_NAME] = SdkConfiguration.packageName
            paramMap[KEY_SDK_VERSION] = SdkConfiguration.sdkVersion
            val user: InternalUser? = LoginManager.instance.getUser()
            if (user != null) {
                paramMap[KEY_HOST]= UserUtils.getState(user)
            }
            return paramMap
        }
}